﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using EQT.Dal;
using EQT.Model;

public partial class login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            if(Session["USER_CONTEXT"]!=null && Request.QueryString[null]=="r")
            {
                FormsAuthentication.SignOut();
                Session.Clear();
            }
        }
    }
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        DaTuser da = DevFuture.Common.WorkContext.AppCtx.GetObject("DaTuser") as DaTuser;
        bool rc= da.Login(textBoxUserID.Text, textBoxPwd.Text);
        if (rc == true) //登入成功
        {
            
            //根据User_ID获取用户信息
            UserContext uc = da.GetUserContext(textBoxUserID.Text);
            if (String.IsNullOrEmpty(uc.RoleID))
            {
                Utility.SiteError(String.Format("没有给用户[{0}]分配合适的角色！", uc.UserName));
                return;
            }
            DaActLog.LogCheckIn(uc.UserID, "上班");
            this.Session.Add("USER_CONTEXT", uc);

            if (Request.QueryString["ReturnUrl"] != null)
            {
                FormsAuthentication.RedirectFromLoginPage(textBoxUserID.Text, false);
            }
            else
            {
                FormsAuthentication.SetAuthCookie(textBoxUserID.Text, false);
                Response.Redirect(FormsAuthentication.DefaultUrl);
            } 
         
        }
        else
        {
            InValid.Text = "用户名和密码错误！";
        }
    }
}
